from typing import Generic, Optional, TypeVar, overload

T = TypeVar('T')
D = TypeVar('D')

class Sequence(Generic[T]):
    def __init__(self, *, origin: 'Optional[Sequence[T]]' = None) -> None:
        self._lastid: int = 0
        self._items: dict[int, T] = dict()
        
        if not origin is None:
            self._items.update(origin._items)
    
    def push(self, obj: T) -> int:
        self._lastid = (id := self._lastid) + 1
        self._items[id] = obj
        return id
    
    def exist(self, id: int) -> bool:
        return id in self._items
    
    @property
    def dict(self) -> dict[int, T]:
        return self._items
    
    @overload
    def get(self, id: int) -> T: ...
    
    @overload
    def get(self, id: int, default: D) -> T | D: ...
    
    def get(self, id: int, default: 'D | ellipsis' = ...) -> T | D:
        if default is ...:
            return self._items[id]
        else:
            return self._items.get(id, default)
    
    def remove(self, id: int) -> None:
        if self.exist(id):
            del self._items[id]
    
    def __repr__(self) -> str:
        if len(self._items):
            return super().__repr__().replace("object", f"object [Seq:\n\t{'\n\t'.join([f"{i:2}: {v}" for (i, v) in self.dict.items()])}]")
        else:
            return super().__repr__().replace("object", f"object [Seq: <Empty>]")